#include "utils.h"
#include <QFile>
#include <QTextStream>
#include <fstream>
#include <QTime>
#include <iostream>

int test(){

//    QVector<Range> vec;
//    QList<Range> result;

//    vec.push_back(Range(3,5));
//    vec.push_back(Range(7,9));

//    result.push_back(Range(1,2));
//    result.push_back(Range(4,8));
//    result.push_back(Range(10,11));

//    Utils::cross(vec, result);



//    QFile file("/home/liyuhui/Downloads/test.txt");
//    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { Q_ASSERT(false); }
//    QTextStream stream(&file);
//    auto pos0 = file.pos();
//    QString line1 = stream.readLine();
//    // auto pos1 = stream.pos();
//    // auto pos2 = file.pos();
//    QString line2 = stream.readLine();
//    QString line3 = stream.readLine();
//    file.close();


    const char * logFilename = "/opt/baidu/engines/NavigationEngine/data.100/SDCard/log/DIAGNOSTIC-0-20191104143959.log";

//    QFile file(logFilename);
//    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { Q_ASSERT(false); }
//    const int BUFFER_SIZE = 1024;
//    char buffer[BUFFER_SIZE];
//    QTime time; time.start();
//    qint64 read;
//    for(;!file.atEnd();){
//        read = file.readLine(buffer, BUFFER_SIZE);
//    }
//    auto t = time.elapsed();
//    std::cout<<(t/1000.0f)<<std::endl;
//    file.close();

    QSet<Line> a;
    a.insert(Line(1,1));

    QFile file(logFilename);
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { Q_ASSERT(false); }
    QString line; qint64 readBytes;
    qint64 fileSize = 0;
    while (Utils::readLine(file, line, readBytes)) {
        fileSize+=readBytes;
    }
    file.close();


//    std::ifstream file("/home/liyuhui/Downloads/test.txt");
//    if (!file) { Q_ASSERT(false); }
//    for(std::string line; std::getline(file, line);){
//        std::streampos pos = file.tellg();
//        int aa = 0;
//    }
//    file.close();


    return 0;
}


